package com.ruoyi.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.merchant.domain.CfMerchantVerification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.CfMerchant;
import com.ruoyi.merchant.service.ICfMerchantService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/merchant")
public class CfMerchantController extends BaseController
{
    @Autowired
    private ICfMerchantService cfMerchantService;

    /**
     * 查询商户列表
     */
    @RequiresPermissions("merchant:merchant:list")
    @GetMapping("/list")
    public TableDataInfo list(CfMerchant cfMerchant)
    {
        startPage();
        List<CfMerchant> list = cfMerchantService.selectCfMerchantList(cfMerchant);
        return getDataTable(list);
    }
    @RequiresPermissions("merchant:merchant:listbyrate")
    @GetMapping("/listbyrate")
    public TableDataInfo listByRate(CfMerchant cfMerchant)
    {
        startPage();
        List<CfMerchant> list = cfMerchantService.getMerchantByMerchantIdOrderByRate(cfMerchant);
        return getDataTable(list);
    }
    /**
     * 导出商户列表
     */
    @RequiresPermissions("merchant:merchant:export")
    @Log(title = "商户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CfMerchant cfMerchant)
    {
        List<CfMerchant> list = cfMerchantService.selectCfMerchantList(cfMerchant);
        ExcelUtil<CfMerchant> util = new ExcelUtil<CfMerchant>(CfMerchant.class);
        util.exportExcel(response, list, "商户数据");
    }

    /**
     * 获取商户详细信息
     */
    @RequiresPermissions("merchant:merchant:query")
    @GetMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") Long merchantId)
    {
        return success(cfMerchantService.selectCfMerchantByMerchantId(merchantId));
    }

    /**
     * 新增商户
     */
    @RequiresPermissions("merchant:merchant:add")
    @Log(title = "商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CfMerchant cfMerchant)
    {
        return toAjax(cfMerchantService.insertCfMerchant(cfMerchant));
    }

    /**
     * 修改商户
     */
    @RequiresPermissions("merchant:merchant:edit")
    @Log(title = "商户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CfMerchant cfMerchant)
    {

        return toAjax(cfMerchantService.updateCfMerchant(cfMerchant));
    }

    /**
     * 删除商户
     */
    @RequiresPermissions("merchant:merchant:remove")
    @Log(title = "商户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable Long[] merchantIds)
    {
        return toAjax(cfMerchantService.deleteCfMerchantByMerchantIds(merchantIds));
    }

    /**
     * 查询用户数通过注册时间
     */
    @RequiresPermissions("merchant:merchant:list")
    @GetMapping("/list/data")
    public TableDataInfo listByData(CfMerchant cfMerchant)
    {
        List<CfMerchant> list = cfMerchantService.selectCfMerchantListByData(cfMerchant);
        return getDataTable(list);
    }

    /**
     * 查询用户数通过注册时间
     */
    @RequiresPermissions("merchant:merchant:list")
    @GetMapping("/list/all")
    public TableDataInfo listAll(CfMerchant cfMerchant)
    {
        List<CfMerchant> list = cfMerchantService.selectCfMerchantList(cfMerchant);
        return getDataTable(list);
    }


    /**
     * 通过查询订单的种类，服务类型等判断这个区中订单的个数
     */
    @RequiresPermissions("merchant:merchant:list")
    @GetMapping("/list/order")
    public TableDataInfo listOrder()
    {
        List<CfMerchant> list = cfMerchantService.selectCfMerchantAndOrderList();
        return getDataTable(list);
    }

}
